import time

def calcTime(func):
        '''
        函数修饰器, 用来计算各个排序算法的执行时间
        最终返回一个 list [temp, time_sum]
        '''
        def warpper (*args, **kwds):
            time_start = time.perf_counter()
            temp = func(*args, **kwds)
            time_end = time.perf_counter()
            time_sum = time_end - time_start
            return [temp, time_sum*1000]
        return warpper

class Solution:
    @calcTime
    def maxSatisfaction(self, test : list) -> int:
        satisfaction = test[:]
        satisfaction.sort(reverse=True)
        presum, ans = 0, 0
        for si in satisfaction:
            if presum + si > 0:
                presum += si
                ans += presum
            else:
                break
        return ans


if __name__ == '__main__':
    test = [-1,-8,0,5,-7]
    a = Solution()
    re = a.maxSatisfaction(test)
    print(re)